
cc.Class({
    extends: cc.Component,

    properties: {
        StartBtnNode:{
            default:null,
            type:cc.Node
        },
        titleNode:{
            default:null,
            type:cc.Node
        },
        loadPrefab:{
            default:null,
            type:cc.Prefab
        }
    },

    show(ne){
        this.node = ne;
        this.node.active = true;
    },
    hide(ne){
        this.node = ne;
        this.node.active =false
    },

    onLoad () {
        this.anim = 'startBtn';
        this.startAnim = this.StartBtnNode.getComponent(cc.Animation);
        this.titleAnim = this.titleNode.getComponent(cc.Animation);
        this.bgNode = this.node.getChildByName('bg');

        this.times = this.startAnim.play('startBtn').duration;
        this.show(this.node);
        this.show(this.StartBtnNode);
       // this.setAnim(this.startAnim,'btnScale');
        this.startAnim.ShowbtnScaleFun = function(){
           this.setAnim(this.startAnim,'btnScale');
        }.bind(this);   
        
    },
    

    start () {
        var titleTimes = this.times * 2000;
        this.show(this.titleNode);
        setTimeout(function(){
            this.playTitle();
        }.bind(this), titleTimes);
       
    },
    playTitle(){
        this.setAnim(this.titleAnim,'action01');
        this.titleAnim.startItemAni = function(){
            this.setAnim(this.titleAnim, 'action02');
        }.bind(this);
        this.titleAnim.ShowAcitionTr = function(){
            this.setAnim(this.titleAnim, 'action03');
        }.bind(this);
    },
    setAnim(ne,anim){
       //  var duration = 0;
        if (this.anim == anim) {
            return
        }
        this.anim = anim;
        this.nodeAnim = ne;
        this.animState=this.nodeAnim.play(anim);
        // duration = this.animState.duration;
        // return duration;
    },

    onClickPlayGame:function(target,data){
        if (data == '开始游戏') {
            this.hide(this.StartBtnNode);
            this.hide(this.titleNode);
           // createLoad(this.node);
           this.getLoadBar();
            cc.director.preloadScene('game',function(){
                cc.director.loadScene("game");
                //console.log(this.getLoadBar());
            });

            //console.log(this.getLoadBar());
        }else{
            console.log('加载失败');
        }
        
       // cc.director.loadScene("game");
    },

    getLoadBar(){
        var load = cc.instantiate(this.loadPrefab);
        this.bgNode.addChild(load);
        load.x = 0;
        load.y = -240;
        this.loadScr = load.getComponent('load');
        this.loadScr.setProgress(1);
       // console.log(loading);
    },

    update (dt) {
    },
});
